package com.example.demo.comment;

import lombok.Data;

@Data
public class AppResult<T> {

    private int code;  //业务状态码
    private String message;
    private T data;

    public static  <T>AppResult<T> success(){
        AppResult appResult = new AppResult();
        appResult.setCode(Encode.SUCCESS.code);
        appResult.setMessage("成功");
        appResult.setData("");
        return appResult;
    }

    public static <T>AppResult<T> success(T data){
        AppResult appResult = new AppResult();
         appResult.setCode(Encode.SUCCESS.code);
         appResult.setData(data);
         return appResult;
    }

    public static <T>AppResult<T> failed(String message){
        AppResult appResult = new AppResult();
        appResult.setCode(Encode.FAILED.code);
        appResult.setMessage(message);
        appResult.setData("");
        return appResult;
    }

    public static <T>AppResult<T> failed(AppResult appResult){
        AppResult appResult1 = new AppResult();
        appResult1.setCode(appResult.getCode());
        appResult1.setMessage(appResult.getMessage());
        appResult1.setData(appResult.getData());
        return appResult1;
    }
}
